package com.chujian.Activities;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.chujian.Adapter.NotificationListAdapter;
import com.chujian.Global.Global;
import com.chujian.model.NotificationBean;
import com.chujian.orderingsystem.R;

public class NotificationListActivity extends Activity implements OnItemClickListener{
	private ListView mListView;
	private List<NotificationBean> mList=new ArrayList<NotificationBean>();
	private NotificationListAdapter mAdapter ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.notification_list);
		mListView=(ListView) findViewById(R.id.lv_notification_list);
		for (int i=Global.mNotiList.size();i>0;i--) {
			  mList.add(Global.mNotiList.get(i-1));
			  Log.i(i+"", Global.mNotiList.get(i-1).toString());
		} 
		
		if(mList!=null){
			mAdapter=new NotificationListAdapter(mList, getApplicationContext());
			mListView.setAdapter(mAdapter);
			mListView.setOnItemClickListener(this);
		}
	}
	public void IbBack(View v){
		finish();
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		Intent intent =new Intent();
		int p=Global.mNotiList.size()-position-1;
		String target=Global.mNotiList.get(p).getTargetName();
		if(target.equals("OrderCurrentListActivity")){
			intent.setClass(getApplicationContext(), OrderCurrentListActivity.class);
			startActivity(intent);
			finish();
		}else if(target.equals("OrderCurrentDetailSellerActivity")){
			intent.setClass(getApplicationContext(), OrderCurrentDetailSellerActivity.class);
			intent.putExtra("orderNotice", Global.mNotiList.get(p).getJsonString());
			startActivity(intent);
			finish();
		}else if(target.equals("OrderCurrentDetailConsumerActivity")){
			intent.setClass(getApplicationContext(), OrderCurrentDetailConsumerActivity.class);
			intent.putExtra("orderNotice", Global.mNotiList.get(p).getJsonString());
			startActivity(intent);
			finish();
		}
	}
}
